

//Make first stage graph!
use "stata data/A1 smart meter install date with interesting info", clear

gen counter = 1

gen days_before = -1*(sm_date - 18870)

capture drop bin
gen bin = round((days_before+4)/7)

replace bin = bin -1 if bin <=0

save "stata data/pre collapse fs", replace


use "stata data/pre collapse fs", clear




fcollapse (sum) counter (mean) pdp defaulted (min) min_sm = sm_date (max) max_sm = sm_date, by(bin)

gen start = 18871
gen sm_bin_date = -7*bin + start
format sm_bin_date %td
replace sm_bin_date = sm_bin_date  +3 if bin > 0
replace sm_bin_date = sm_bin_date  -3 if bin < 0

label variable sm_bin_date "Smartmeter installation date"
label variable defaulted "Percent of customers defautlted"

keep if inrange(bin,-27,27)

replace pdp = 0 if bin < 0


*october 26, 2011 - 18926
*july 13, 2011 - 18815	
		
capture drop shade
gen shade = 1
	
twoway  (area shade sm_bin_date if inrange(sm_bin_date,18815,18871), color("38 38 38") fi(48) lcolor(white)) ///
		(area shade sm_bin_date if inrange(sm_bin_date,18871,18926), color("166 166 166") fi(48) lcolor(white)) ///
		(scatter defaulted sm_bin_date, color(black))		 ///
		, xline(18871)   xline(18815 18926, lcolor(gray) lpattern(shortdash)) ///
		xtitle("Date of interval data first collected", height(5)) ///
		graphregion(color(white)) bgcolor(white) ylabel(.2 .4 .6 .8 1,grid glcolor(gs15) angle(0)) ///
		ytitle("Percent of customers defaulted" "to peak pricing for 2015 summer") leg(off) ///
		text(.8 18843 "Before") text(.73 18843 "(Eligible)", size(small)) ///
		text(.8 18900 "After") text(.73 18900 "(Ineligible)", size(small)) ///
		xlabel(18871 `" "September 1"  "2011" "' ///
		18815 `" "July 7"  "2011" "' ///
		18748 `" "May 1"  "2011" "' ///
		18926 `" "Oct 26"  "2011" "' ///
		18993 `" "Jan 1"  "2012" "', labsize(small))
		
		*xlabel(  18871    18815 18926 18993 18748, labsize(small) ) ///

*fi from  http://www.stata.com/statalist/archive/2008-09/msg01449.html
graph export "latex/A1_2014_changeover_FS_graph.pdf", replace 